

package com.hazelcast.replicatedmap.impl.record;

import com.hazelcast.replicatedmap.impl.ReplicatedMapService;

import static com.hazelcast.internal.namespace.NamespaceUtil.callWithNamespace;

/**
 * This is a {@link com.hazelcast.config.InMemoryFormat#OBJECT} based
 * {@link ReplicatedRecordStore} implementation
 *
 * @param <K> key type
 * @param <V> value type
 */
public class ObjectReplicatedRecordStorage<K, V> extends AbstractReplicatedRecordStore<K, V> {

    public ObjectReplicatedRecordStorage(String name, ReplicatedMapService replicatedMapService, int partitionId) {
        super(name, replicatedMapService, partitionId);
    }

    @Override
    public Object unmarshall(Object key) {
        String userCodeNamespace = replicatedMapConfig.getUserCodeNamespace();
        return callWithNamespace(nodeEngine, userCodeNamespace, () -> nodeEngine.toObject(key));
    }

    @Override
    public Object marshall(Object key) {
        String userCodeNamespace = replicatedMapConfig.getUserCodeNamespace();
        return callWithNamespace(nodeEngine, userCodeNamespace, () -> nodeEngine.toObject(key));
    }
}
